home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Family Forum 259
/
IND_GIANT.BIN
/
Xtras
/
Animation Wizard.dir
/
00004_Script_IncrDecrValue
< prev
next >
Wrap
Text File
|
1997-05-10
|
5KB
|
159 lines
-- IncrDecrValue script
property iType -- #int or #real
property iMin
property iMax
property iInc
property ichField
property ichButton
property iLastValidValue
property iFieldName
property iCastNumNormal
property iCastNumIncr
property iCastNumDecr
on birth me, type, min, max, incAmount, chText, theFieldName
set iType = type
set iMin = min
set iMax = max
set iInc = incAmount
set ichField = chText
set ichButton = ichField + 1
set iLastValidValue = iMin
set iFieldName = theFieldName
mSetValue(me, iLastValidValue)
return me
end birth
on mHit me
-- Assumes that the increment version of the button is one past
-- the normal state, and the decrement version is two past the
-- the normal state in the cast.
set castNumNormal = the castnum of sprite ichButton
set iCastNumNormal = castNumNormal
set iCastNumIncr = castNumNormal + 1
set iCastNumDecr = castNumNormal + 2
set iLastValidValue = field ( the castNum of sprite ichField)
set lowerLimitBeepedFlag = FALSE
set upperLimitBeepedFlag = FALSE
set mouseDownFlag = TRUE
set firstTimeFlag = TRUE
repeat while mouseDownFlag
if rollOver(ichButton) then
set okToChangeValueFlag = TRUE
if the mouseV <= the locV of sprite ichButton then -- upper half of rocker control = increase
set lowerLimitBeepedFlag = FALSE
set sign = 1
if (iLastValidValue = iMax) then -- at upper limit
set okToChangeValueFlag = FALSE
if not(upperLimitBeepedFlag) then
beep
set upperLimitBeepedFlag = TRUE
set the castNum of sprite ichButton = castNumNormal
updateStage
end if
end if
else -- lower half of rocker control = decrease
set upperLimitBeepedFlag = FALSE
set sign = -1
if (iLastValidValue = iMin) then -- at lower limit
set okToChangeValueFlag = FALSE
if not(lowerLimitBeepedFlag) then
beep
set lowerLimitBeepedFlag = TRUE
set the castNum of sprite ichButton = castNumNormal
updateStage
end if
end if
end if -- check for upper or lower half of rocker
if okToChangeValueFlag then
mChangeValue(me, sign)
end if
else -- not currently rolled over the button
set the castNum of sprite ichButton = castNumNormal
updateStage
end if
if firstTimeFlag then -- this allows for easy one step increments
set firstTimeFlag = FALSE
wait(15)
end if
set mouseDownFlag = the mouseDown
end repeat
set the castNum of sprite ichButton = castNumNormal
updateStage
end mHit
on mChangeValue me, sign
if sign = 1 then
set the castNum of sprite ichButton = iCastNumIncr
else
set the castNum of sprite ichButton = iCastNumDecr
end if
updateStage
-- next figure out what the next value ( in the indicated direction ) within the
-- appropriate domain is going to be
if iType = #int then
set iLastValidValue = (integer( iLastValidValue / iInc ) * iInc ) + ( iInc * sign )
else if iType = #real then
set iLastValidValue = (( iLastValidValue / iInc ) * iInc ) + ( iInc * sign )
end if
-- finally, insert the new value ( properly formatted ) into the field
put iLastValidValue into field ( the castNum of sprite ichField)
end mChangeValue
on mGetValue me
set theTypedInString = the text of field iFieldName
set newValue = value(theTypedInString)
if iLastValidValue <> newValue then -- user typed in something new
set iLastValidValue = newValue
end if
return iLastValidValue
end mGetValue
on mSetValue me, theNewValue
if (theNewValue < iMin) or (theNewValue > iMax) then
alert("Bad value passed to IncrDecrValue:" && theNewValue)
return
end if
set iLastValidValue = theNewValue
set the text of field iFieldName = string(iLastValidValue)
updateStage
end mSetValue
on mValidate me
set theTypedInString = the text of field iFieldName
set newValue = value(theTypedInString)
if voidP(newValue) then -- not numeric
alert("The value in the " & iFieldName & " field must be numeric")
mSetValue(me, iMin)
return FALSE
end if
if (newValue > iMax) or (newValue < iMin) then
alert("Please enter a value between " & iMin & " and " & iMax & " into the " &¼
iFieldName & " field.")
mSetValue(me, iMin)
return FALSE
end if
return TRUE
end mValidate